<?php
namespace app\http;

use think\worker\Server;

class Worker extends Server
{
	// protected $socket = 'websocket://0.0.0.0:2346';
	protected $socket = 'tcp://172.24.55.59:9501';

    public function onMessage($connection, $data)
    {
        $data = iconv("EUC-CN", "UTF-8", $data);
        $connection->send($data);
    }

    /**
     * 当连接建立时触发的回调函数
     * @param $connection
     */
    public function onConnect($connection)
    {
        $connection->send("success");
    }

    /**
     * 当连接断开时触发的回调函数
     * @param $connection
     */
    public function onClose($connection)
    {
        
    }

    /**
     * 当客户端的连接上发生错误时触发
     * @param $connection
     * @param $code
     * @param $msg
     */
    public function onError($connection, $code, $msg)
    {
        echo "error $code $msg\n";
    }

    /**
     * 每个进程启动
     * @param $worker
     */
    public function onWorkerStart($worker)
    {

    }
}
